package wnhz.com.business.groupshop.fragment;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import wnhz.com.business.R;
import wnhz.com.business.base.BaseActivity;
import wnhz.com.business.base.BaseFragment;
import wnhz.com.business.base.BaseRVAdapter;
import wnhz.com.business.base.BaseViewHolder;
import wnhz.com.business.groupshop.bean.HotSeachBean;
import wnhz.com.business.groupshop.ui.CommodityClassifyActivity;
import wnhz.com.business.groupshop.ui.HotXiangQingActivity;
import wnhz.com.business.groupshop.ui.SearchActivity;
import wnhz.com.business.impl.ActionBarClickListener;
import wnhz.com.business.view.TranslucentActionBar;


public class HomeFragment4 extends BaseFragment implements View.OnClickListener, ActionBarClickListener {

    @BindView(R.id.actionbar)
    TranslucentActionBar actionbar;
    @BindView(R.id.recycler_head)
    RecyclerView recyclerHead;
    @BindView(R.id.img_shuiguo)
    ImageView imgShuiguo;
    @BindView(R.id.img_meizhang)
    ImageView imgMeizhang;
    @BindView(R.id.ll_meirong)
    LinearLayout llMeirong;
    @BindView(R.id.ll_hufu)
    LinearLayout llHufu;
    @BindView(R.id.ll_caizhuang)
    LinearLayout llCaizhuang;
    @BindView(R.id.ll_xiangshui)
    LinearLayout llXiangshui;
    @BindView(R.id.ll_nanshihuli)
    LinearLayout llNanshihuli;
    @BindView(R.id.img_dianqi)
    ImageView imgDianqi;
    @BindView(R.id.img_muying)
    ImageView imgMuying;
    @BindView(R.id.img_jiafang)
    ImageView imgJiafang;
    @BindView(R.id.img_qita)
    ImageView imgQita;

    private View view;
    private BaseActivity activity;
    private HotSeachBean hotSeachBean;
    private List<HotSeachBean> itemhand = new ArrayList<>();

    public static HomeFragment4 newInstance() {
        HomeFragment4 homeFragment4 = new HomeFragment4();
        return homeFragment4;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_home_fragment4, container, false);
        ButterKnife.bind(this, view);
        activity = (BaseActivity) getActivity();
        actionbar.setData("", 0, null, 1, null, 1, this);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            actionbar.setStatusBarHeight(getStatusBarHeight());
        }

        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        initview();
        setRecyclerHead();
    }

    @Override
    public void onClick(View v) {

    }

    @Override
    public void onLeftClick() {

    }

    @Override
    public void onRightClick() {

    }

    @Override
    public void onEditTextClick() {
        startActivity(new Intent(getActivity(), SearchActivity.class));
    }


    private void initview() {
        recyclerHead.setLayoutManager(new GridLayoutManager(getContext(), 4, LinearLayoutManager.VERTICAL, false));
        itemhand.clear();
        itemhand.add(new HotSeachBean("暖宝宝"));
        itemhand.add(new HotSeachBean("牛皮糖"));
        itemhand.add(new HotSeachBean("手表"));
        itemhand.add(new HotSeachBean("手环"));
        itemhand.add(new HotSeachBean("男包"));
        itemhand.add(new HotSeachBean("手机壳"));
        itemhand.add(new HotSeachBean("花伞"));
        itemhand.add(new HotSeachBean("五娘液"));
    }

    private void setRecyclerHead() {
        recyclerHead.setAdapter(new BaseRVAdapter(getContext(), itemhand) {
            @Override
            public int getLayoutId(int viewType) {
                return R.layout.item_hotseach_head;
            }

            @Override
            public void onBind(BaseViewHolder holder, int position) {
                holder.getTextView(R.id.tv_name).setText(itemhand.get(position).getName());
                final String names = holder.getTextView(R.id.tv_name).getText() + "";
                holder.getTextView(R.id.tv_name).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        startActivity(new Intent(getActivity(), HotXiangQingActivity.class));
//                        startActivityForResult(new Intent().putExtra("types",names),0);
                    }
                });
            }

        });
    }


    @OnClick({R.id.img_shuiguo, R.id.img_meizhang, R.id.ll_meirong, R.id.ll_hufu, R.id.ll_caizhuang, R.id.ll_xiangshui, R.id.ll_nanshihuli, R.id.img_dianqi, R.id.img_muying, R.id.img_jiafang, R.id.img_qita})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            //水果
            case R.id.img_shuiguo:
                startActivityForResult(new Intent(getActivity(), CommodityClassifyActivity.class).putExtra("type", 0), 0);
                break;
            //美妆
            case R.id.img_meizhang:
                startActivityForResult(new Intent(getActivity(), CommodityClassifyActivity.class).putExtra("type", 1), 1);
                break;
            //美容
            case R.id.ll_meirong:
                startActivityForResult(new Intent(getActivity(), CommodityClassifyActivity.class).putExtra("type", 2), 2);
                break;
            //护肤
            case R.id.ll_hufu:
                startActivityForResult(new Intent(getActivity(), CommodityClassifyActivity.class).putExtra("type", 3), 3);
                break;
            //彩妆
            case R.id.ll_caizhuang:
                startActivityForResult(new Intent(getActivity(), CommodityClassifyActivity.class).putExtra("type", 4), 4);
                break;
            //香水
            case R.id.ll_xiangshui:
                startActivityForResult(new Intent(getActivity(), CommodityClassifyActivity.class).putExtra("type", 5), 5);
                break;
            //男士护理
            case R.id.ll_nanshihuli:
                startActivityForResult(new Intent(getActivity(), CommodityClassifyActivity.class).putExtra("type", 6), 6);
                break;
            //电器
            case R.id.img_dianqi:
                startActivityForResult(new Intent(getActivity(), CommodityClassifyActivity.class).putExtra("type", 7), 7);
                break;
            //母婴
            case R.id.img_muying:
                startActivityForResult(new Intent(getActivity(), CommodityClassifyActivity.class).putExtra("type", 8), 8);
                break;
            //家纺
            case R.id.img_jiafang:
                startActivityForResult(new Intent(getActivity(), CommodityClassifyActivity.class).putExtra("type", 9), 9);
                break;
            //更多
            case R.id.img_qita:
                break;
        }
    }


}
